home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / dkbtrace / pbmplus / source / pbm / pbmtoplo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-06  |  1.6 KB  |  76 lines

  1. /* pbmtoplot.c - read a portable bitmap and produce a UNIX-format plot file.
  2. **
  3. ** Copyright (C) 1990 by Arthur David Olson.
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #include <stdio.h>
  14. #include "pbm.h"
  15.  
  16. static void
  17. puttwo( i )
  18.     int i;
  19.     {
  20.     (void) putchar(i);
  21.     (void) putchar(i >> 8);
  22.     }
  23.  
  24. void
  25. main( argc, argv )
  26.     int argc;
  27.     char* argv[];
  28.     {
  29.     FILE* ifp;
  30.     register bit** bits;
  31.     register int row, col, scol;
  32.     int    rows, cols;
  33.  
  34.     pbm_init( &argc, argv );
  35.  
  36.     if ( argc > 2 )
  37.     pm_usage( "[pbmfile]" );
  38.  
  39.     ifp = (argc == 2) ? pm_openr( argv[1] ) : stdin;
  40.  
  41.     bits = pbm_readpbm( ifp, &cols, &rows );
  42.  
  43.     pm_close( ifp );
  44.  
  45.     (void) putchar( 's' );
  46.     puttwo( 0 );
  47.     puttwo( 0 );
  48.     puttwo( rows - 1 );
  49.     puttwo( cols - 1 );
  50.     for ( row = 0; row < rows; ++row )
  51.     {
  52.     for ( col = 0; col < cols; ++col )
  53.         {
  54.         if ( bits[row][col] == PBM_WHITE )
  55.         continue;
  56.         scol = col;
  57.         while ( ++col < cols && bits[row][col] == PBM_BLACK )
  58.         ; /* nothing */
  59.         --col;
  60.         if ( col == scol )
  61.         (void) putchar( 'p' );
  62.         else
  63.         {
  64.         (void) putchar( 'l' );
  65.         puttwo( scol );
  66.         puttwo( rows - 1 - row );
  67.         }
  68.         puttwo( col );
  69.         puttwo( rows - 1 - row );
  70.         }
  71.     }
  72.  
  73.     pm_close (stdout);
  74.     exit( 0 );
  75.     }
  76.